package com.thinkgem.jeesite.modules.sys.api;

import com.qiniu.common.QiniuException;
import com.qiniu.common.Zone;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Configuration;
import com.qiniu.util.Auth;
import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.ResponseResult;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.sys.entity.Dict;
import com.thinkgem.jeesite.modules.sys.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * restful demo
 * 所有的api返回值均为ResponseResult，在ResponseResult内赋予相关的对象
 * @author yinyanan
 * @version 2019-02-28
 */
@RestController
@RequestMapping(value = "${wechatPath}/rest/util")
public class UtilApiController extends BaseController {
    @Autowired
    private DictService dictService;

    /**
     *
     * @Title: searchListByType
     * @author: yinyanan
     * @date: 2019年02月28日 上午9:30:50
     * @Description: 新增泌乳信息(新增和修改)
     * @param: @param lactation
     * @param: @param request
     * @param: @param response
     * @param: @return
     * @return: ResponseResult
     * @throws:
     */
    @RequestMapping(value = "/searchListByType", method = RequestMethod.POST)
    public ResponseResult searchListByType(@RequestBody Dict dict, HttpServletRequest request, HttpServletResponse response){
        List<Dict> dictList = dictService.searchListByType(dict);
        return ResponseResult.success(dictList);
    }

    /**
     * @author Zhang Xingliang
     * @description 获取七牛云文件上传token
     * @date 14:19 2019/6/28
     * @params []
     * @return com.thinkgem.jeesite.common.persistence.ResponseResult
     **/
    @RequestMapping(value = "/qiniuToken" )
    public ResponseResult getQiniuToken(){
        Auth auth = Auth.create(Global.getConfig("accessKey"), Global.getConfig("secretKey"));
        String upToken = auth.uploadToken( Global.getConfig("bucket"));
        Map<String,String> map = new HashMap<>();
        map.put("token",upToken);
        map.put("expires","");
        return ResponseResult.success(map);
    }

    /**
     * @author Zhang Xingliang
     * @description 获取七牛云文件上传token
     * @date 14:19 2019/6/28
     * @params []
     * @return com.thinkgem.jeesite.common.persistence.ResponseResult
     **/
    @ResponseBody
    @RequestMapping(value = "recogToken" )
    public ResponseResult getRecogToken(){
        Map<String,String> map = new HashMap<>();
        map.put("invoiceKey",Global.getConfig("invoiceKey"));
        map.put("invoiceSecret",Global.getConfig("invoiceSecret"));
        return ResponseResult.success(map);
    }

}
